package com.xyht.medicine_management_system.modules.order.controller;


import com.xyht.medicine_management_system.auth.util.JwtTokenUtil;
import com.xyht.medicine_management_system.common.commonReturn.ResponseResult;
import com.xyht.medicine_management_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.medicine_management_system.modules.order.entity.req.MmsOrderRefundReq;
import com.xyht.medicine_management_system.modules.order.service.MmsOrderRefundService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 订单退款表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2023-12-14
 */
@RestController
@SecretBody
@RequestMapping("/refund")
public class MmsOrderRefundController {
    @Resource
    private MmsOrderRefundService mmsOrderRefundService;
    @Resource
    private JwtTokenUtil jwtTokenUtil;

    @ApiOperation("申请退款")
    @PostMapping("/submit")
    public ResponseResult submitRefund(@RequestBody MmsOrderRefundReq refundReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsOrderRefundService.submitRefund(refundReq, userId);
    }

    @ApiOperation("同意退款")
    @CrossOrigin // 跨域
    @PostMapping("/agree")
    public ResponseResult agreeRefund(@RequestBody MmsOrderRefundReq refundReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsOrderRefundService.agreeRefund(refundReq, userId);
    }

    @ApiOperation("拒绝退款")
    @PostMapping("/refuse")
    public ResponseResult refuseRefund(@RequestBody MmsOrderRefundReq refundReq, HttpServletRequest request) {
        String userId = jwtTokenUtil.getUserIdByRequest(request);
        return mmsOrderRefundService.refuseRefund(refundReq, userId);
    }

    @ApiOperation("获取全部退款信息")
    @GetMapping("/allRefund")
    public ResponseResult getAllRefund(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                       @RequestParam(value = "searchStr", required = false) String searchStr,
                                       @RequestParam(value = "status", required = false) Integer status) {
        return mmsOrderRefundService.getAllRefund(pageNum, pageSize, searchStr, status);
    }

    @ApiOperation("获取退款详情信息")
    @GetMapping("/detail")
    public ResponseResult getRefundDetail(@RequestParam("refundId") String refundId, HttpServletRequest request) {
        return mmsOrderRefundService.getRefundDetail(refundId);
    }

}

